﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataLib.Accounts.Bus;
using DataLib.Common;
using System.Data;
using Microsoft.Reporting.WebForms;
using Ewts.Code;

namespace Ewts.RDLC
{
    public partial class QueryUnprocessRDLC : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
            {
                bindMonth();
                if (Session["UserInfo"] == null)
                {
                    Response.Redirect("/Accounts/Login.aspx");
                    return;
                }
                else
                {
                    ListItem item = new ListItem();
                    item.Text = "--请选择--";
                    item.Value = "";
                    DataLib.BLL.City bllLib = new DataLib.BLL.City();
                    // 处理地
                    dropBcity.DataSource = bllLib.GetList(" flag1 ='01'");
                    dropBcity.DataTextField = "cityname";
                    dropBcity.DataValueField = "cityname";
                    dropBcity.DataBind();
                    dropBcity.Items.Insert(0, item);


                    dropGcity.DataSource = bllLib.GetList(" flag1 ='02'");
                    dropGcity.DataTextField = "cityname";
                    dropGcity.DataValueField = "cityname";
                    dropGcity.DataBind();
                    dropGcity.Items.Insert(0, item);
                }

            }

           
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            QueryUnprocessReportView.Visible = true;
            Search();
        }
        /// <summary>
        /// 绑定财务结算月
        /// </summary>
        protected void bindMonth()
        {
            int year = DateTime.Now.Year;

            ListItem listitem = new ListItem((year + 1).ToString() + "年", (year + 1).ToString());
            dropYear.Items.Add(listitem);
            listitem = new ListItem(year.ToString() + "年", year.ToString());
            dropYear.Items.Add(listitem);
            listitem = new ListItem((year - 1).ToString() + "年", (year - 1).ToString());
            dropYear.Items.Add(listitem);

            dropYear.SelectedValue = year.ToString();
            dropMonth.SelectedValue = DateTime.Now.Month.ToString().PadLeft(2, '0');

        }

        protected void Search()
        {

            string loadnum = this.txtLoadnum.Text;            //loadnum
            string cum = this.txtCum.Text;                    //客户名
            string instorageno = this.txtInStorageNo.Text;    //入库编号
            string goodscode = this.txtGoodsCode.Text;        //物料编码
            DateTime? time1 = null;
            DateTime? time2 = null;
            if (!string.IsNullOrEmpty(txtTime1.Text))
                time1 = DateTime.Parse(txtTime1.Text);
            if (!string.IsNullOrEmpty(txtTime2.Text))
                time2 = DateTime.Parse(txtTime2.Text);
            string rubbishcode = txtrubbishcode.Text;
            string continNo = txtcontinNo.Text;
            string remark = txremark.Text;
            string instorageClassify = this.ddlInstorageClassify.SelectedValue;//入库方式
            string cleanmonth = hidcleanmonth.Value;        //结算月
            string bcity = dropBcity.SelectedValue;
            string gcity = dropGcity.SelectedValue;
            if (txtStartHour.Text != "")
            {
                time1 = ((DateTime)time1).AddHours(int.Parse(txtStartHour.Text));
            }
            if (txtStartMinute.Text != "")
            {
                time1 = ((DateTime)time1).AddMinutes(int.Parse(txtStartMinute.Text));
            }
            if (txtStartSecond.Text != "")
            {
                time1 = ((DateTime)time1).AddSeconds(int.Parse(txtStartSecond.Text));
            }

            if (txtEndHour.Text != "")
            {
                time2 = ((DateTime)time2).AddHours(int.Parse(txtEndHour.Text));
            }
            if (txtEndMinute.Text != "")
            {
                time2 = ((DateTime)time2).AddMinutes(int.Parse(txtEndMinute.Text));
            }
            if (txtEndSecond.Text != "")
            {
                time2 = ((DateTime)time2).AddSeconds(int.Parse(txtEndSecond.Text));
            }
            DataTable dt = new DataLib.BLL.unProcessed().getunProcessedList(loadnum, cum, instorageno, goodscode, time1, time2, rubbishcode, continNo, instorageClassify, cleanmonth, remark,bcity,gcity);

            ReportDataSource rds = new ReportDataSource("DataSet1", dt);
            QueryUnprocessReportView.LocalReport.DataSources.Clear();
            QueryUnprocessReportView.LocalReport.DataSources.Add(rds);
            new RDLCPrinter().FillRow(dt, 3, 20, 20);
            QueryUnprocessReportView.LocalReport.Refresh();
        }

    }
}